<template>
    <div>
        <Card style="margin-bottom:10px;">
          <p slot="title">
            <Icon type="ios-analytics"></Icon>
            用户信息
          </p>
          <Row type="flex" justify="center" align="middle" class="countto-page-row">
              <template v-for="(item,key) in userinfo">
                  <Labelinfo :key="key" :labelwidth="100" :labeltext="item.title" :infovalue="item.value"></Labelinfo>
              </template>
          </Row>
        </Card>
        <Card style="margin-bottom:10px;">
          <p slot="title">
            <Icon type="ios-analytics"></Icon>
            会员关系
          </p>
          <Row type="flex" justify="center" align="middle" class="countto-page-row">
              <template v-for="(item,key) in vip">
                  <Labelinfo :key="key" :labelwidth="100" :labeltext="item.title" :infovalue="item.value"></Labelinfo>
              </template>
          </Row>
        </Card>
        <Card style="margin-bottom:10px;">
          <p slot="title">
            <Icon type="ios-analytics"></Icon>
            资金情况
          </p>
          <Row type="flex" justify="center" align="middle" class="countto-page-row">
              <template v-for="(item,key) in money">
                  <Labelinfo :key="key" :labelwidth="100" :labeltext="item.title" :infovalue="'¥' + item.value"></Labelinfo>
              </template>
          </Row>
        </Card>
        <Card style="margin-bottom:10px;">
          <p slot="title">
            <Icon type="ios-analytics"></Icon>
            实名信息
          </p>
          <Row type="flex" justify="center" align="middle" class="countto-page-row">
              <template v-for="(item,key) in realnameinfo">
                  <Labelinfo :key="key" :labelwidth="100" :labeltext="item.title" :infovalue="item.value"></Labelinfo>
              </template>
          </Row>
        </Card>
        <Card style="margin-bottom:10px;">
          <p slot="title">
            <Icon type="ios-analytics"></Icon>
            信用卡信息
          </p>
          <Row justify="center" align="middle" class="countto-page-row">
              <Table :columns="Creditcardinfo_head" :data="Creditcardinfo_data"></Table>
          </Row>
        </Card>
        <Card style="margin-bottom:10px;">
          <p slot="title">
            <Icon type="ios-analytics"></Icon>
            余额通道信息
          </p>
          <a href="#" slot="extra" @click.prevent="refreshpassageway">
            <Icon type="ios-loop-strong"></Icon>
            刷新
          </a>
          <Row justify="center" align="middle" class="countto-page-row">
              <Table :columns="passageway_head" :data="passageway_data"></Table>
          </Row>
        </Card>
    </div>
</template>
<script>
import Labelinfo from '_c/infoshow/labelinfo';
import { getAuthkey } from '@/libs/util'
import { getUserdetail, getPassagewayData } from '@/api/data';
export default {
  name: 'userinfo',
  data () {
    return {
      userinfo: [],
      vip: [
        /* {title: '好的朋友', value: '章三'},
        {title: '间接朋友', value: '平台'},
        {title: '我的朋友', value: '0'},
        {title: '朋友圈', value: '0'}, */
      ],
      money: [],
      realnameinfo: [],
      Creditcardinfo_head: [
        {
          title: '卡号',
          key: 'bank_no',
          render: (h,params) => {
                let tmdata = '';
                if(params.row.bank_no){
                   tmdata = params.row.bank_no.substring(0,3)+'******'+params.row.bank_no.substring(params.row.bank_no.length-3)
                }
                return h('div',[
                    h('span',tmdata)
                ])
            }
        },
        {
          title: '绑定手机',
          key: 'tel',
          render: (h,params) => {
                let tmdata = '';
                if(params.row.tel){
                   tmdata = params.row.tel.substring(0,3)+'******'+params.row.tel.substring(params.row.tel.length-3)
                }
                return h('div',[
                    h('span',tmdata)
                ])
            }
        },
        {
          title: '银行',
          key: 'bank_name'
        },
        {
          title: 'cvv2',
          key: 'cvv2'
        },
        {
          title: '有效期',
          key: 'date'
        },
        {
          title: '还款日',
          key: 'repay_data'
        },
        {
          title: '账单日',
          key: 'bill_data'
        },
        {
          title: '额度',
          key: 'balance'
        },
        {
          title: '状态',
          key: 'status',
          render: (h, params) => {
              return h('div', [
                  h('span', params.row.status === 1?'通过验证': '未通过验证')
              ])
          }
        },
        {
          title: '创建时间',
          key: 'create_time'
        }
      ],
      Creditcardinfo_data: [],
      passageway_head: [
        {
          title: '通道',
          key: 'name'
        },
        {
          title: '编码',
          key: 'code'
        },
        {
          title: '类型',
          key: 'type',
          render: (h, params) => {
              return h('div', [
                  h('span',params.row.type === 1? '消费': '还款')
              ])
          }
        },
        {
          title: '可操作余额',
          key: 'waybalance'
        },
        {
          title: '通道基础费率',
          key: 'way_rate',
          render: (h, params) => {
              return h('div', [
                  h('span', params.row.way_rate + '%')
              ])
          }
        },
        {
          title: '是否启用',
          key: 'open',
          render: (h, params) => {
              return h('div', [
                  h('span', params.row.open === 1?'开启': '关闭')
              ])
          }
        }
      ],
      passageway_data: []
    }
  },
  created() {
      this.refreshpassageway()
      this.getUserInfo()
  },
  components: {
    Labelinfo
  },
  methods: {
      refreshpassageway() {
          let data = {
              auth_key: getAuthkey(),
              uid: this.$router.history.current.params.id
          }
          getPassagewayData(data).then(res => {
              this.passageway_data = res.data.data.data
          },err =>{
              this.$Message.error('获取通道数据失败');
          })
      },
      getUserInfo() {
          let data = {
              auth_key: getAuthkey(),
              uid: this.$router.history.current.params.id
          }
          getUserdetail(data).then(res => {
              if(res.data.code !== 200){
                this.$Message.error(res.data.error)
                return
              }
              this.Creditcardinfo_data = res.data.data.card
              this.userinfo = [
                {title: '用户ID', value: res.data.data.auth.uid},
                {title: '登录名', value: res.data.data.user.u_name},
                {title: '用户名', value: res.data.data.user.u_name},
                {title: '微信id', value: ''},
                {title: '创建时间', value: res.data.data.user.create_time}
              ]
              this.money = [
                {title: '历史余额', value: res.data.data.user.all_balance},
                {title: '可用余额', value: res.data.data.user.now_balance},
                {title: '消费余额', value: res.data.data.user.plan_balance},
                {title: '开通余额', value: res.data.data.user.fun_balance},
                {title: '代还余额', value: res.data.data.user.cash_balance},
                {title: '冻结余额', value: res.data.data.user.fro_balance}
              ]
              this.realnameinfo = [
                {title: '姓名', value: res.data.data.auth.real_name},
                {title: '身份证', value: res.data.data.auth.real_no},
                {title: '卡号', value: res.data.data.auth.bank_no},
                {title: '绑定手机', value: res.data.data.auth.tel},
                {title: '银行', value: res.data.data.auth.bank_name},
                {title: '银行电话', value: res.data.data.auth.bank_tel},
                {title: '省', value: res.data.data.auth.bank_province},
                {title: '城市', value: res.data.data.auth.bank_city},
                {title: '状态', value: res.data.data.auth.status === 1?'通过验证': '未通过验证'},
                {title: '绑定时间', value: res.data.data.auth.create_time}
              ]
          }, err => {
              this.$Message.error(err?err: '获取用户信息失败');
          })
      }
  }
}
</script>
